﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace LiveEduWizard.Filter
{
    public class ContainsFilterRule : IFilterRule
    {
        private readonly string text;

        public ContainsFilterRule(string text)
        {
            this.text = text;
        }

        public bool IsMatch(AppointmentViewModel appointment)
        {
            if ((appointment.Details != null && appointment.Details.Contains(text))
                || (appointment.Location != null && appointment.Location.Contains(text))
                || (appointment.Organizer != null && (appointment.Organizer.DisplayName.Contains(text) || appointment.Organizer.EmailAddress.Contains(text)))
                || (appointment.Subject != null && appointment.Subject.Contains(text))
                || (appointment.Title != null && appointment.Title.Contains(text)))
                return true;

            if (appointment.Attendees != null)
            {
                foreach (var attendee in appointment.Attendees)
                    if (attendee.DisplayName.Contains(text) || attendee.EmailAddress.Contains(text))
                        return true;
            }

            if (appointment.Related != null)
            {
                foreach (var related in appointment.Related)
                    if (related.Title.Contains(text))
                        return true;
            }

            return false;
        }
    }
}
